package com.github.xuemingyu.springboot.acticitycloud.controller.api;

import com.bidanet.bdcms.core.bean.ApiResult;
import com.github.xuemingyu.springboot.acticitycloud.entity.UserInfo;
import com.github.xuemingyu.springboot.acticitycloud.service.UserInfoService;
import org.apache.catalina.servlet4preview.http.HttpServletRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Objects;

/**
 * \* Created with IntelliJ IDEA.
 * \* User: xmy
 * \* Date: 2019/2/12
 * \* Time: 17:46
 * \
 */
@RestController
@RequestMapping("/userInfo")
public class UserInfoApiController {
    @Autowired
    private UserInfoService userInfoService;

    @RequestMapping("/findOne")
    public ApiResult findOne(HttpServletRequest request) {
        String userId = request.getHeader("userId");
        UserInfo byUserId = userInfoService.findByUserId(userId);
        if (Objects.isNull(byUserId)){
            byUserId = new UserInfo();
        }
        return ApiResult.success(byUserId);
    }
}
